//
//  Kratos_ForgotVCPresenter_Kra.m
//  kk_framework
//
//  Created by 7yao.top on 2018/11/10.
//  Copyright © 2018年 7yao.top. All rights reserved.
//

#import "Kratos_ForgotVCPresenter_Kra.h"
#import "Kratos_RegisiterView.h"
#import "k_const.h"
#import "Kratos_RegisiterView.h"
#import "Kratos_RegiterInputView.h"
#import "Kratos_CountDownButton.h"
#import "Kratos_inputCode.h"
#import "UIView+Toast.h"
#import "MBProgressHUD+HUD.h"

@interface Kratos_ForgotVCPresenter_Kra() <Kratos_RegisiterViewDelegate>
@property (weak, nonatomic) UIViewController *weakVC;
@end

@implementation Kratos_ForgotVCPresenter_Kra
- (void)Kratos_usageLogic
{
    if ([self.view1 isKindOfClass:[Kratos_RegisiterView class]]) {
        Kratos_RegisiterView *registerViwe =  (Kratos_RegisiterView *)self.view1;
        registerViwe.delegate  = self;
    }
    
    
}

///忘记密码
- (void)Kratos_getmsgCodeClick:(NSString *)phoneNumber {
    
    __weak typeof(self) weakSelf = self;
    Kratos_RegisiterView *registerView =  (Kratos_RegisiterView *)weakSelf.view1;
    
    [self.Kra_httpClient Kratos_noGeneralpost:[NSString stringWithFormat:@"/index/pub/smsrqcode?username=%@&type=2",phoneNumber] Kratos_parameters:nil onSuccess:^(Kratos_HttpResponse * _Nullable response) {
        if (response.Kra_status == Kratos_HttpResponseStatusSuccess)
        {
            if ([response.Kra_content isKindOfClass:[NSDictionary class]]) {
                NSDictionary *dict = response.Kra_content;
                [weakSelf.view1 makeToast:dict[@"msg"]];
            }
            
        }else
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"stopCountDown" object:nil];
        }
        
    } onFail:^(Kratos_HttpResponse * _Nullable response) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"stopCountDown" object:nil];
        [registerView makeToast:response.Kra_content];
        
    }];
    
    
}
- (void)Kratos_present
{
    
}
- (void)Kratos_dissmissVC
{
    [_weakVC dismissViewControllerAnimated:false completion:nil];
}
- (void)setViewController:(UIViewController *)ViewController
{
    _weakVC = ViewController;
    
}

///重置密码点击了
- (void)Kratos_registerClick:(UIButton *)btn {
    __weak typeof(self) weakSelf = self;
    Kratos_RegisiterView *registerView =  (Kratos_RegisiterView *)weakSelf.view1;
    
    NSString *phone = registerView.Kra_registerInputView.Kra_phoneNumber;
    NSString *password = registerView.Kra_registerInputView.Kra_phonePWD;
    NSString *sms = registerView.Kra_registerInputView.Kra_phonecode;
    
    if (phone == nil || phone.length == 0) {
        [registerView makeToast:@"请填写手机号码"];
        return;
    }
    
    
    if (sms == nil || sms.length == 0) {
        [registerView makeToast:@"请填验证码"];
        return;
    }
    if (password == nil || password.length == 0) {
        [registerView makeToast:@"请填写密码"];
        return;
    }
    
    
    

    [self.Kra_httpClient Kratos_post:@"/user/pub/resetpwdapi" Kratos_parameters:@{@"username":registerView.Kra_registerInputView.Kra_phoneNumber,@"password":registerView.Kra_registerInputView.Kra_phonePWD,@"type":@"2",@"sms":registerView.Kra_registerInputView.Kra_phonecode} Kratos_onSuccess:^(Kratos_HttpResponse * _Nullable response) {
        if (response.Kra_status == Kratos_HttpResponseStatusSuccess)
        {
            
            if ([response.Kra_content[@"code"] integerValue] != 1) {
                if (response.Kra_content[@"msg"])
                {
                    [MBProgressHUD showMessage:response.Kra_content[@"msg"] toView:registerView];
                }
                return;
            }
            
            [registerView makeToast:response.Kra_content[@"msg"]];
        }
    } Kratos_onFail:^(Kratos_HttpResponse * _Nullable response) {
        
        
        
        [registerView makeToast:response.Kra_content];
        
        
    }];
    
}



- (void)setView:(NSObject *)View
{
    
}
- (void)Kratos_onFail:(id)clientInfo Kratos_errCode:(NSInteger)errCode errInfo:(NSString *)errInfo {
    
}

- (void)Kratos_onSuccess:(id)responseObject {
    
}

@end
